<template>
  <el-dialog
     :title="!dataForm.id ? '新增' : '信息回复'"
    :close-on-click-modal="false"
    :before-close="closeHandle"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">

    <el-form-item label="评价内容" prop="contents">
      <textarea style="width: 100%;height: 170px;border-radius: 15px;background-color:  #F0F8FF" disabled="disabled" v-model="dataForm.contents" placeholder="评价内容"></textarea>
    </el-form-item>
    <el-form-item label="图片" prop="imgurl">
      <div class="feedback-back">
        <div class="feedback-back-img-box">
          <div class="feedback-back-img" @click="icon(item)" v-for="(item,index) in imglist" :key="index">
            <img class="feedback-back-style" :src="item">
          </div>
        </div>
        <div v-if="show" position="center" class="popup" >
          <div class="show-box" @click="close()">
            <img class="feedback-back-ico" :src="bigicon" @click="close()">
          </div>
        </div>
      </div>
    </el-form-item>
    <el-form-item label="评价回复" prop="replyinfo">
      <textarea style="width: 100%;height: 170px" v-model="dataForm.replyinfo"></textarea>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" :disabled="subable" @click="dataFormSubmit()" v-if="">确定</el-button>
    </span>
  </el-dialog>
</template>

<style scoped>
  .feedback-back{
    padding: 15px 0;
  }
  .feedback-back-img-box{
    width: 100%;
    overflow: hidden;
    display: block;
  }
  .feedback-back-img{
    width: 20%;
    height: 150px;
    overflow: hidden;
    float: left;
    margin-bottom: 10px;
    padding: 5px;
  }
  .feedback-back-style{
    width: 100%;
    height: 100%;
    border:1px solid #d7d7d7;
    border-radius: 10px;
  }
  .show-box{
    background: rgba(0,0,0,0.5);
    width: 100%;
    height: 100%;
    z-index:99999;
    text-align: center;
    line-height: 60;
  }
  .feedback-back-ico{
    width: 600px;
    margin: 0 auto;
  }
  .popup{
    position: fixed;
    width: 100%;
    bottom: 0;
    z-index: 999999;
    top:0;
    left: 0;
  }
</style>

<script>
  export default {
    data () {
      return {
        subable: false,
        disable: true,
        visible: false,
        show: false,
        imglist: [],
        bigicon: '',
        dataForm: {
          id: 0,
          customerid: '',
          typename: '',
          nickname: '',
          roomtypeid: '',
          roomtypename: '',
          receiptid: '',
          contents: '',
          imgurl: '',
          replyinfo: '',
          replytime: '',
          commenttime: ''
        },
        dataRule: {
          replyinfo: [
            { required: true, message: '回复内容不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init: function (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.subable = false
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            // 修改
            this.$http({
              url: this.$http.adornUrl(`/comment/comment/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.customerid = data.comment.customerid
                this.dataForm.nickname = data.comment.nickname
                this.dataForm.roomtypename = data.comment.roomtypename
                this.dataForm.roomtypeid = data.comment.roomtypeid
                this.dataForm.receiptid = data.comment.receiptid
                this.dataForm.contents = data.comment.contents
                if (data.comment.imgurl !== '' && data.comment.imgurl !== undefined){
                  this.imglist = data.comment.imgurl.split(',')
                } else {
                  this.imglist = []
                }
                this.dataForm.replyinfo = data.comment.replyinfo
                this.dataForm.replytime = data.comment.replytime
                this.dataForm.commenttime = data.comment.commenttime
              }
            })
          }
        })
      },
      icon (item) {
        this.show = !this.show
        this.bigicon = item
      },
      close () {
        this.show = !this.show
      },
      // 弹窗关闭时
      closeHandle () {
        this.$emit('refreshDataList')
        this.visible = false
      },
      // 表单提交
      dataFormSubmit () {
        this.subable = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/comment/comment/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'replyinfo': this.dataForm.replyinfo
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.disable = false
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1000,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          } else {
            this.subable = false
          }
        })
      }
    }
  }
</script>
